package mashibing.class17;

import java.util.HashSet;
import java.util.Set;

/**
 * 打印一个字符串的全部子序列，要求不要出现重复字面值的子序列
 */
public class Class17_3_PrintAllSubsquences {

    // s -> "abc" ->
    public static Set<String> subs(String s) {
        char[] chars = s.toCharArray();
        Set<String> ans = new HashSet<>();
        f(chars, 0, "", ans);
        return ans;
    }

    public static void f(char[] chars, int index, String path, Set<String> ans) {
        if (index == chars.length) {
            ans.add(path);
        } else {
            f(chars, index + 1, path, ans);
            f(chars, index + 1, path + chars[index], ans);
        }
    }

    public static void main(String[] args) {
        Set<String> abc = subs("abc");
        for (String s : abc) {
            System.out.println(s);
        }
    }
}
